#include"InetAddr.hh"

InetAddr::InetAddr()
{}

InetAddr::~InetAddr()
{}

InetAddr::InetAddr(string ip,int port)
{
    _addr.sin_family=AF_INET;
    _addr.sin_port=htons(port);
    _addr.sin_addr.s_addr=inet_addr(ip.c_str());
}

InetAddr::InetAddr(const struct sockaddr_in& rhs)
    :_addr(rhs)
{

    /* _addr.sin_family     =rhs._addr.sin_family ; */
    /* _addr.sin_port       =rhs._addr.sin_port   ; */
    /* _addr.sin_addr.s_addr=rhs._addr.sin_addr.s_addr; */
}

const struct sockaddr_in* InetAddr::getaddr() const
{
    return &_addr;
}

int InetAddr::port() const
{
    return ntohs(_addr.sin_port);
}

string InetAddr::ip() const
{
    return string(inet_ntoa(_addr.sin_addr));
}
